package com.microservice.postservice.controller;


import com.microservice.commonutils.R;
import com.microservice.commonutils.userVo.UserInfoVo;
import com.microservice.postservice.client.UserInfoClient;
import com.microservice.postservice.entity.PostComment;
import com.microservice.postservice.entity.PostContent;
import com.microservice.postservice.entity.vo.PostCommentVo;
import com.microservice.postservice.entity.vo.UcenterMemberVo;
import com.microservice.postservice.service.PostCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author leesin
 * @since 2022-05-14
 */
@RestController
@RequestMapping("/postservice/postcomment")
public class PostCommentController {

    @Autowired
    private PostCommentService postCommentService;

    @Autowired
    private UserInfoClient userInfoClient;

    @PostMapping("insertpost")
    public R insertpost(@RequestBody PostComment postComment){
        boolean save = postCommentService.save(postComment);
        if (save){
            return R.ok().data("postContent",postComment);
        }else {
            return R.error();
        }

    }
    @GetMapping("getCommentByPostId/{postId}")
    public R getCommentByPostId(String postId){
//        List<PostComment> postComment = postCommentService.getPostComment(postId);
        List<PostCommentVo> postComment = postCommentService.getPostComment(postId);
        return R.ok().data("postComent",postComment);
    }
    @GetMapping("getUserInfo/{id}")
    public R getUserInfo(@PathVariable(value = "id")String userId){
        UserInfoVo userInfoById = userInfoClient.getUserInfoById(userId);

        System.out.println("comment  "+userInfoById.toString());
       return R.ok().data("userInfo",userInfoById);
    }
}

